package br.uninove.ic.texture;

public class Histogram {

    int histogram[];
    
    IGrayScaleImage imgHistogram;
    
    public Histogram(IGrayScaleImage img){
           int maxCount = 0, histogram[] = new int[256];
           for (int row = 0; row < img.getHeight(); row++)
               for (int col = 0; col <  img.getWidth(); col++)
                   if (++histogram[img.getPixel(col, row)] > maxCount)
                       maxCount = histogram[img.getPixel(col, row)];
           
           final int HEIGHT_MAX_HISTOGRAM = 250;
           imgHistogram = new GrayScaleImage(256, HEIGHT_MAX_HISTOGRAM + 10);
           imgHistogram.initImage(255);
           for (int i = 0; i < 256; i++){
               
               //tracar a linha correspondente para cada nivel de cinza no histograma
               int peak =  (int) (histogram[i] / (double) maxCount * HEIGHT_MAX_HISTOGRAM);
               for(int j=imgHistogram.getHeight()-1; j > imgHistogram.getHeight() - peak; j--){
                   imgHistogram.setPixel(i, j, 0);
               }
           }
           
    }
    
    public int[] getHistogram(){
        return histogram;
    }
    
    
    public IGrayScaleImage getImgHistogram(){
        return imgHistogram;
    }
    
    public int peakMaximo(){
        //calcula
        return 0;
    }
    
    //tarefas
    //calcular a media, mediana, minimo e maximo do histograma
    
}
